

* Open log
capture log close
log using "Data analysis\cbld-description03-fig03", replace text


* ********************************************************
* Fig. 3. Coalition-building dynamics: A typical model run
* ********************************************************

* Programme:	cbld-description03-fig03.do
* Project:		Council coalition building
* Author:		Frank Haege, Department of Politics and Administration, University of Limerick
* Contact:		frank.haege@ul.ie

* Description
*************
* This do-file generates a graph illustrating the coalition-building dynamics 
* of a typical model run for a membership size of twenty-five states and 
* a voting threshold of 72 per cent. The indivdual panels show member states positions
* at the beginning of the model run and after each of three negotiation rounds.
* Note that the arrows, indicating changes in positions between two negotiation
* rounds, and the numbers, indicating the sequence of those changes, were added manually
* in Stata's graph editor.


* Set up Stata
version 11
clear all
macro drop _all
set linesize 80
set more off

* Load member state position data from typical model run
insheet using "Experiments\Experiment02\cbld-model-121020-exp02-world.csv", clear

* Drop redundant variables
drop alternativecoalition alternativecoalitionsize blockingminority winningmajority who


* Generate and recode variables for plotting
********************************************

* Rename variables
rename myfirstcriterionsize mycoalsize

* Label variables
label var mycoalsize "Coalition size"
label var xcor "Issue 1"
label var ycor "Issue 2"
label var time "Time" 

* Identify size of coalitions
tab mycoalsize if time == 0
tab mycoalsize if time == 1
tab mycoalsize if time == 2
tab mycoalsize if time == 3

* Generate marker symbol size weights as a function of coalition size	
local 1 = 1*1.5
local 2 = 2*1
local 3 = 3*1
local 4 = 4*1
local 8 = 8*1
local 9 = 9*1
local 12 = 12*1
local 13 = 13*1


* Plot of member state positions after initiation of model
**********************************************************

twoway (scatter ycor xcor if time == 0 & mycoalsize == 1, /*
	*/ msymbol(o) msize(*`1') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 0 & mycoalsize > 1, /*
	*/ xlabel(-10 -5:10) ylabel(-10 -5:10) /*
	*/ xscale(range(-10 10)) yscale(range(-10 10)) /*
	*/ msymbol(i) mlabel(mycoalsize) mlabsize(small) /*
	*/ mlabpos(center) mlabcolor(white) mfcolor(gray) /*
	*/ aspectratio(1) legend(off) subtitle("Initial Positions")) /*
	*/ , saving("Data analysis\Graphs\cbld-description03-fig03a.gph", replace)


* Plot of member state positions after first round of position changes
**********************************************************************

twoway (scatter ycor xcor if time == 1 & mycoalsize == 1, /*
	*/ msymbol(o) msize(*`1') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 1 & mycoalsize == 3, /*
	*/ msymbol(o) msize(*`3') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 1 & mycoalsize == 4, /*
	*/ msymbol(o) msize(*`4') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 1 & mycoalsize == 8, /*
	*/ msymbol(o) msize(*`8') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 1 & mycoalsize == 2, /*
	*/ msymbol(o) msize(*`2') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 1 & mycoalsize > 1, /*
	*/ xlabel(-10 -5:10) ylabel(-10 -5:10) /*
	*/ xscale(range(-10 10)) yscale(range(-10 10)) /*
	*/ msymbol(i) mlabel(mycoalsize) mlabsize(small) /*
	*/ mlabpos(center) mlabcolor(white) mfcolor(gray) /*
	*/ aspectratio(1) legend(off) subtitle("After Round 1")) 	/*
	*/ , saving("Data analysis\Graphs\cbld-description03-fig03b.gph", replace)	


* Plot of member state positions after second round of position changes
***********************************************************************
	
twoway (scatter ycor xcor if time == 2 & mycoalsize == 3, /*
	*/ msymbol(o) msize(*`3') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 2 & mycoalsize == 9, /*
	*/ msymbol(o) msize(*`9') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 2 & mycoalsize == 12, /*
	*/ msymbol(o) msize(*`12') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 2 & mycoalsize == 1, /*
	*/ msymbol(o) msize(*`1') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 2 & mycoalsize > 1, /*
	*/ xlabel(-10 -5:10) ylabel(-10 -5:10) /*
	*/ xscale(range(-10 10)) yscale(range(-10 10)) ylabel(-10 -5:10) /*
	*/ msymbol(i) mlabel(mycoalsize) mlabsize(small) /*
	*/ mlabpos(center) mlabcolor(white) mfcolor(gray) /*
	*/ aspectratio(1) legend(off) subtitle("After Round 2"))	/*
	*/ , saving("Data analysis\Graphs\cbld-description03-fig03c.gph", replace)	


* Plot of member state positions after third round of position changes
**********************************************************************
	
twoway (scatter ycor xcor if time == 3 & mycoalsize == 12, /*
	*/ msymbol(o) msize(*`12') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 3 & mycoalsize == 13, /*
	*/ msymbol(o) msize(*`13') mcolor(white) mfcolor(gray)) /*
	*/ (scatter ycor xcor if time == 3 & mycoalsize > 1, /*
	*/ xlabel(-10 -5:10) ylabel(-10 -5:10) /*
	*/ xscale(range(-10 10)) yscale(range(-10 10)) /*
	*/ msymbol(i) mlabel(mycoalsize) mlabsize(small) /*
	*/ mlabpos(center) mlabcolor(white) mfcolor(gray) /*
	*/ aspectratio(1) legend(off) subtitle("After Round 3"))  /*
	*/, saving("Data analysis\Graphs\cbld-description03-fig03d.gph", replace)


* Combine plots of member state positions at different point in time into a single graph
****************************************************************************************
	
graph combine /*
	*/ "Data analysis\Graphs\cbld-description03-fig03a.gph" /*
	*/ "Data analysis\Graphs\cbld-description03-fig03b.gph" /*
	*/ "Data analysis\Graphs\cbld-description03-fig03c.gph" /*
	*/ "Data analysis\Graphs\cbld-description03-fig03d.gph" /*
	*/ , xsize(3) ysize(3) imargin(tiny) saving("Data analysis\Graphs\cbld-description03-fig03.gph", replace)
	
	
* Exit do-file
log close
exit
